import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslint from 'vite-plugin-eslint2'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { fileURLToPath, URL } from 'node:url'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), eslint({ cache: false }), vueJsx()],
  server: {
    open: true,
    proxy: {
      '/api': {
        target: 'http://localhost:4000/',
        // 兼容基于名字的虚拟主机
        changeOrigin: true,
        // 路径重写， 把api换位‘’
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@use "@/styles/variables.scss";'
      }
    }
  }
})
